/*!
    \copyright  Copyright (c) 2025 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \addtogroup accessory_device_service
    @{
    \brief      Contains private variables and functions to be used within accessory_device_service only
*/

#ifndef ACCESSORY_DEVICE_SERVICE_PRIVATE_H_
#define ACCESSORY_DEVICE_SERVICE_PRIVATE_H_

#include "accessory_device_service.h"

#ifdef INCLUDE_ACCESSORY_DEVICE_SERVICE

#include <bdaddr.h>
#include <task_list.h>
#include <panic.h>

/*! \brief Specifies maximum supported accessory connections */
#define ACCESSORY_DEVICE_SERVICE_MAX_CONNECTIONS   (2)

/*! Client task list initial list */
#define ACCESSORY_DEVICE_SERVICE_CLIENT_LIST_INIT_CAPACITY 1

/*! \brief Different states of an accessory */
typedef enum
{
    ACCESSORY_DEVICE_SERVICE_STATE_IDLE,
    ACCESSORY_DEVICE_SERVICE_STATE_PAIRING,
    ACCESSORY_DEVICE_SERVICE_STATE_CONNECTED,
} accessory_device_service_state_t;

/*! \brief Accessory device information */
typedef struct
{
    /*! Address associated with the accessory */
    tp_bdaddr tp_addr;

    /*! Type of accessory */
    accessory_device_service_device_type_t type;

    /*! Current state of accessory */
    accessory_device_service_state_t state;
} accessory_device_t;

/*! \brief Data associated with accessory device service */
typedef struct
{
    /*! Accessory device service task */
    TaskData task_data;

    /*! Client lists for notifications */
    TASK_LIST_WITH_INITIAL_CAPACITY(ACCESSORY_DEVICE_SERVICE_CLIENT_LIST_INIT_CAPACITY) client_list;

    /*! List of accessory devices */
    accessory_device_t accessory_devices[ACCESSORY_DEVICE_SERVICE_MAX_CONNECTIONS];
} accessory_device_service_data_t;

/*! Accessory module data */
extern accessory_device_service_data_t accessory_device_service_data;

/*! \brief Get pointer to the Accessory device service module data structure */
#define accessoryDeviceService_GetData() (&accessory_device_service_data)

/*! \brief Get the task associated with Accessory device service */
#define accessoryDeviceService_GetTask() (&accessoryDeviceService_GetData()->task_data)

/*! Get the client list for the accessory device service. */
#define accessoryDeviceService_GetClientList() (task_list_flexible_t *)(&accessoryDeviceService_GetData()->client_list)

/*! \brief Resets the accessory device service module
*/
void AccessoryDeviceService_Reset(void);

/*! \brief Create a new accessory device entry.
    This function creates a new entry for an accessory device in the accessory device service.
    It initializes the device entry with the provided Bluetooth address, device type, and initial state.

    \param tp_addr Pointer to the tp address of the accessory device.
    \param type The type of the accessory device.
    \param state The initial state of the accessory device.

    \return Pointer to the newly created accessory device entry, or NULL if the creation fails.
 */
accessory_device_t* AccessoryDeviceService_CreateDeviceEntry(const tp_bdaddr *tp_addr,
                                                       accessory_device_service_device_type_t type,
                                                       accessory_device_service_state_t state);

/*! \brief Retrieve the accessory device entry for a given tp address.

    This function searches for and returns the accessory device entry associated with the specified tp_bdaddr.
    If no matching entry is found, the function returns NULL.

    \param tp_addr Pointer to the transport Bluetooth address (tp_bdaddr) to search for.

    \return Pointer to the accessory device entry (accessory_device_t) if found, otherwise NULL.
*/
accessory_device_t* AccessoryDeviceService_GetDeviceEntryForTpAddr(const tp_bdaddr *tp_addr);

#endif /* INCLUDE_ACCESSORY_DEVICE_SERVICE */

#endif /* ACCESSORY_DEVICE_SERVICE_PRIVATE_H_ */